<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>酒店后台管理系统</title>
  <link rel="stylesheet" href="css/layui.css">
  <script src="js/jquery.min.js"></script>
  <script>
  	$(function(){
  		var url = "ws://169.254.106.77:8080/WebSocketHandler/";
		var ws = null;
		//连接服务器
		var userName = $("#userName").val();
		url = url + userName; //传递用户名
		//创建对象，连接服务器
		ws=new WebSocket(url);
		//给ws对象绑定事件
		//连接事件
		ws.onopen = function(){
			console.info("连接服务器成功");
		}
		//接收到消息
		ws.onmessage = function(result){
			alert("你有一条待处理消息");
		}
		//关闭连接
		ws.onclose = function(){
			console.info("断开连接");
		}
		
		$("#pass_message").click(function(){
			var message=$("#pass_message").val();
			if(ws!=null){
				ws.send(message); //发送消息
			}
		})
		
		$("#nopass_message").click(function(){
			var message=$("#nopass_message").val();
			if(ws!=null){
				ws.send(message); //发送消息
			}
		})
			
		//断开连接
		$("#cancel").click(function(){
			if(ws!=null){
				ws.close();
			}
		});
  	})
	  function findRoomType(){		
		  $.ajax({
				url:"/offline/findRtype",
				type:"post",
				data:{
					checkIn:$("#start-time").val(),
					checkOut:$("#end-time").val(),
				},
				success:function(data){
					var table=$("<table class='layui-table' lay-skin='line' lay-size='sm'></table>");
					var colgroup=$("<colgroup></colgroup>").text("<col width='150'>"
					+"<col width='200'>"
					+"<col>");
					var thead=$("<thead></thead>");
					var tr = $("<tr></tr>");
					var th1=$("<th style='width: 300px;'></th>").text("房型名称");
					var th2 = $("<th></th>").text("窗型");
					var th3 = $("<th></th>").text("早餐");
					var th4 = $("<th></th>").text("汤水");
					var th5 = $("<th></th>").text("价格");
					var th6 = $("<th></th>").text("数量");
					var th7 = $("<th></th>").text("前台付款全网最低");
					tr.append(th1);
				    tr.append(th2);
				    tr.append(th3);
				    tr.append(th4);
				    tr.append(th5);
				    tr.append(th6);
				    tr.append(th7);
					var tbody = $("<tbody></tbody>");
					for(var i=0; i<data.length;i++){
						var tr1 = $("<tr></tr>");
					    var td1=$("<td class='rtname_btn'></td>").text(data[i].rtname);
					    var td2=$("<td class='rwindow'></td>").text(data[i].rwindow);
					    var td3=$("<td class='rfood'></td>").text(data[i].rfood);
					    var td4=$("<td class='rspring'></td>").text(data[i].rspring);
					    var td5=$("<td style='color: rgb(238 44 44);font-size: 15px; font-weight: 600;' class='rprice'></td>").text(data[i].rprice);
					    var td6=$("<td class='rnumber'></td>" ).text(data[i].number);
					    var content='<button type="button" class="layui-btn layui-btn-xs " onclick="add(this)" id="'+i+'">'
						+'<i class="layui-icon">&#xe608;</i> 预定'
						+'</button>'
						+'<button type="button" class="layui-btn layui-btn-xs layui-btn-danger " onclick="zero(this)" id="'+i+'">清空</button>';
					    var td7=$("<td></td>").html(content);
					    tr1.append(td1);
					    tr1.append(td2);
					    tr1.append(td3);
					    tr1.append(td4);
					    tr1.append(td5);
					    tr1.append(td6);
					    tr1.append(td7);
					    tbody.append(tr1);
					}
					thead.append(tr);
					table.append(thead);
					table.append(tbody);
					$(".table_class").html(table);
				}
			})
	  }
	  function add(a){
		  var start_time=new Date($("#start-time").val());
		  var end_time=new Date($("#end-time").val());
		  var day = parseInt(end_time - start_time)/86400000;
		  alert(day);
		  var classnumber = $(".rnumber");
		  var id = a.getAttribute("id")
		  var i = $(".rnumber").eq(id).text();
		  var number = Number(i) + 1;
		  $(".rnumber").eq(id).text(number);
		  var totalNumber = 0;
		  var totalPrice = 0;
		  var rtname = "";
		  var q=0;
		  for(var index=0;index < classnumber.length;index++){
			  totalNumber = Number(totalNumber)+Number($(".rnumber").eq(index).text());
			  for(var k=0;k<Number($(".rnumber").eq(index).text());k++){
				  rtname = rtname+'<input type="hidden" value='+$(".rtname_btn").eq(index).text()+' name="orderDetails['+q+'].roomType.rtname">'
				  +'<input type="hidden" value='+$(".rwindow").eq(index).text()+' name="orderDetails['+q+'].roomType.rwindow">'
				  +'<input type="hidden" value='+$(".rfood").eq(index).text()+' name="orderDetails['+q+'].roomType.rfood">'
				  +'<input type="hidden" value='+$(".rspring").eq(index).text()+' name="orderDetails['+q+'].roomType.rspring">'
				  +'<input type="hidden" value='+$(".rprice").eq(index).text()+' name="orderDetails['+q+'].roomType.rprice">';
				  q=Number(q)+1;
			  }
			  var price = Number($(".rprice").eq(index).text())*Number($(".rnumber").eq(index).text())*day;
			  totalPrice = Number(totalPrice)+Number(price);
		  }
		  $("#add_rtname").html(rtname);
		  $("#rtotalprice").html("￥"+totalPrice);
		  var guest = "";
		  for(var j = 0; j < totalNumber; j++){
			  guest = guest+'<div class="layui-form-item" >'
			  +'<label class="layui-form-label">入住人</label>'
			   +'<div class="layui-input-inline">'
			   +'<input type="text" name="orderDetails['+j+'].guest.gname" lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">'
			   +'</div>'
			   +'<label class="layui-form-label">身份证</label>'
			   +'<div class="layui-input-inline">'
			   +'<input type="text" name="orderDetails['+j+'].guest.gidcard" lay-verify="identity" placeholder="请输入身份证" autocomplete="off" class="layui-input">'
			   +'</div>'
			   +'</div>';
		  }
		  $("#add_guest").html(guest);
	  }
	  function zero(a){
		  var start_time=new Date($("#start-time").val());
		  var end_time=new Date($("#end-time").val());
		  var day = parseInt(end_time - start_time)/86400000;
		  var classnumber = $(".rnumber");
		  var i = a.getAttribute("id")
		  $(".rnumber").eq(i).text(0);
		  var totalNumber = 0;
		  var totalPrice = 0;
		  var rtname="";
		  var q=0;
		  for(var index=0;index < classnumber.length;index++){
			  totalNumber = Number(totalNumber)+Number($(".rnumber").eq(index).text());
			  for(var k=0;k<Number($(".rnumber").eq(index).text());k++){

				  rtname = rtname+'<input type="hidden" value='+$(".rtname_btn").eq(index).text()+' name="orderDetails['+q+'].roomType.rtname">'
				  +'<input type="hidden" value='+$(".rwindow").eq(index).text()+' name="orderDetails['+q+'].roomType.rwindow">'
				  +'<input type="hidden" value='+$(".rfood").eq(index).text()+' name="orderDetails['+q+'].roomType.rfood">'
				  +'<input type="hidden" value='+$(".rspring").eq(index).text()+' name="orderDetails['+q+'].roomType.rspring">'
				  +'<input type="hidden" value='+$(".rprice").eq(index).text()+' name="orderDetails['+q+'].roomType.rprice">';
				  q=Number(q)+1;
			  }
			  var price = Number($(".rprice").eq(index).text())*Number($(".rnumber").eq(index).text())*day;
			  totalPrice = Number(totalPrice)+Number(price);
		  }
		  $("#add_rtname").html(rtname);
		  
		  $("#rtotalprice").html("￥"+totalPrice);
		  var guest = "";
		  for(var j = 0; j < totalNumber; j++){
			  guest = guest+'<div class="layui-form-item" >'
			  +'<label class="layui-form-label">入住人</label>'
			   +'<div class="layui-input-inline">'
			   +'<input type="text" name="orderDetails['+j+'].guest.gname" lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">'
			   +'</div>'
			   +'<label class="layui-form-label">身份证</label>'
			   +'<div class="layui-input-inline">'
			   +'<input type="text" name="orderDetails['+j+'].guest.gidcard" lay-verify="identity" placeholder="请输入身份证" autocomplete="off" class="layui-input">'
			   +'</div>'
			   +'</div>';
		  }
		  $("#add_guest").html(guest);
	  }

  </script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo">酒店后台管理系统</div>
    <!-- 头部区域（可配合layui已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
      <!-- <li class="layui-nav-item"><a href="">订单管理</a></li>
      <li class="layui-nav-item"><a href="">营业查询</a></li>
      <li class="layui-nav-item"><a href="">系统设置</a></li>
      <li class="layui-nav-item">
        <a href="javascript:;">其它系统</a> -->
        <dl class="layui-nav-child">
          <dd><a href="test.html">邮件管理</a></dd>
          <dd><a href="">消息管理</a></dd>
          <dd><a href="">授权管理</a></dd>
        </dl>
      </li>
    </ul>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item">
        <a href="javascript:;">
          <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
          贤心
        </a>
        <dl class="layui-nav-child">
          <dd><a href="">基本资料</a></dd>
          <dd><a href="">安全设置</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item"><a href="logout">退了</a></li>
    </ul>
  </div>
  
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree"  lay-filter="test">
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">订单管理</a>
          <dl class="layui-nav-child">
            <dd><a href="/html/offline.html">线下开单</a></dd>
            <dd><a href="/checkin.html">线下开房</a></dd>
            <dd><a href="/html/checkout.html">宾客结账</a></dd>
            <dd><a href="/html/order.html">订单管理</a></dd>
          </dl>
        </li>
       <li class="layui-nav-item">
          <a href="javascript:;">营业查询</a>
          <dl class="layui-nav-child">
            <dd><a href="/selguest.html">入住宾客查询</a></dd>
            <dd><a href="/turnover.html">日/月营业查询</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">系统设置</a>
          <dl class="layui-nav-child">
            <dd><a href="/vip.html">VIP设置</a></dd>
        		<dd><a href="/discount.html">计费设置</a></dd>
        		<dd><a href="/room.html">房间设置</a></dd>
				<dd><a href="/admin.html">操作员设置</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item"><a href="/html/confirm.html">推送消息</a></li>
      </ul>
    </div>
  </div>
  
  <div class="layui-body">
  <input type="hidden" id="userName" value="后台">
    <!-- 内容主体区域 -->
	<form class="layui-form" action="/offline/car">
		
		<div class="layui-order-message">
			下单信息
			<hr class="layui-bg-green">
		</div>
		<div class="layui-form-item">
		  <div class="layui-inline">
			<label class="layui-form-label">入住时间</label>
			<div class="layui-input-inline">
			  <input type="text" name="checkIn" id="start-time" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
			</div>
		  </div>
		  <div class="layui-inline">
			<label class="layui-form-label">至</label>
			<div class="layui-input-inline">
					<input type="text" name="checkOut" id="end-time" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">	      </div>
		  </div>
		  <div class="layui-inline">
		  	<button type="button" class="layui-btn layui-btn-sm" onclick="findRoomType()">确定</button>
		  </div>
		</div>
		
		<div class="table_class" style="width:1000px; margin-left: 50px;">
			
		</div>
		
		<div id="add_rtname">
		
		</div>
		
	  <div class="layui-form-item">
	    <label class="layui-form-label">房间总价</label>
	    <div class="layui-input-inline" style="font-size: 22px;line-height: 36px;color: rgb(205,0,0);" id="rtotalprice">
			￥0
	    </div>
	  </div>
	  
	  <div class="layui-order-message">
	  	入住信息
	  	<hr class="layui-bg-green">
	  </div>
	  
	  <div id="add_guest">
	  
	  </div>
	  
	  <div class="layui-form-item">
	    <div class="layui-input-block">
	      <button class="layui-btn" lay-submit="" lay-filter="demo1">提交订单</button>
	      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
	    </div>
	  </div>
	</form>
  </div>
  
  <div class="layui-footer">
    <!-- 底部固定区域 -->
    © 版权归酒店所有
  </div>
</div>
<script src="layui.js"></script>
<script>
//JavaScript代码区域
layui.use('element', function(){
  var element = layui.element;
  
});
layui.use('laydate', function(){
	var laydate = layui.laydate;

	laydate.render({
	  elem: '#start-time'
	  ,min: 0
	  ,max: 30
	});
	laydate.render({
	  elem: '#end-time'
	  ,min: 1
	  ,max: 30
	});
});
</script>
</body>
</html>